<template>
  <div class="base-container">
    <t-form ref="form" :data="queryParams" label-width="80" @submit="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}" @reset="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="系统模块" name="title">
            <t-input
              v-model="queryParams.title"
              placeholder="请输入系统模块"
              clearable
              style="width: 240px"
            />
          </t-form-item>
          <t-form-item label="操作人员" name="operName">
            <t-input
              v-model="queryParams.operName"
              placeholder="请输入操作人员"
              clearable
              style="width: 240px;"
            />
          </t-form-item>
          <t-form-item label="类型" name="businessType">
            <t-select
              v-model="queryParams.businessType"
              placeholder="操作类型"
              clearable
              :options="dict.type.sys_oper_type"
              style="width: 240px"
            >
            </t-select>
          </t-form-item>
          <t-form-item label="状态" name="status">
            <t-select
              v-model="queryParams.status"
              placeholder="操作状态"
              clearable
              style="width: 240px"
              :options="dict.type.sys_common_status"
            >
            </t-select>
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <t-table
      rowKey="operId"
      :data="data"
      :columns="columns"
      hover
      :pagination="pagination"
      :loading="dataLoading"
    >
      <template #businessType="{row}">
        {{ row.businessType.toString() | filterByDict(dict.type.sys_oper_type) }}
      </template>
      <template #status="{row}">
        {{ row.status.toString() | filterByDict(dict.type.sys_common_status) }}
      </template>
      <template #op="{row}">
        <t-button size="small"  @click="dialog.formData = row;dialog.open=true"
                  variant="text" class="t-button-link">
          <t-icon name="info-circle" slot="icon"/>
          详情
        </t-button>
      </template>
    </t-table>
    <oper-detail :formData="dialog.formData" :visible.sync="dialog.open" v-if="dialog.open"></oper-detail>
  </div>
</template>

<script>
import OperDetail from "./components/oper-detail.vue"

export default {
  name: "oper-log-index",
  dicts: ["sys_oper_type", "sys_common_status"],
  components: {
    OperDetail
  },
  data(){
    return {
      dialog: {
        formData: {},
        open: false,
      },
      data: [],
      columns: [
        {
          colKey: "title",
          title: "系统模块",
          align: "center",
        },
        {
          colKey: "businessType",
          title: "操作类型",
          align: "center",
        },
        {
          colKey: "requestMethod",
          title: "请求方式",
          align: "center",
        },
        {
          colKey: "operName",
          title: "操作人员",
          align: "center",
        },
        {
          colKey: "operIp",
          title: "操作地址",
          align: "center",
        },
        {
          colKey: "status",
          title: "操作状态",
          align: "center",
        },
        {
          colKey: "operTime",
          title: "操作时间",
          align: "center",
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 120
        },
      ],
      dataLoading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: '',
        operName: '',
        businessType: '',
        status: ''
      },
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination,pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  created(){
    this.getList();
  },
  methods:{
    getList(){
      this.dataLoading = true;
      this.$api.system.log.oper(this.queryParams).then(response => {
        this.pagination.total = response.total;
        this.data = response.rows;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    }
  }
}
</script>

<style scoped>

</style>
